package com.example.es.controller;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class TestDemo1 {
    public static void main(String[] args) {
        int i = Runtime.getRuntime().availableProcessors();
        System.out.println(i);
    }
    public static void main1(String[] args) throws IOException {
        String[] split = logPathunil("E:\\zkqa\\logs").split(",");
        String recevie = split[0];
        String finish = split[1];
        File file = new File(recevie);
        if(!file.exists()) {
            file.createNewFile();
        }
        File file1 = new File(finish);
        if(!file1.exists()) {
            file1.createNewFile();
        }

    }


    private static String logPathunil(String logpath) {
        File file = new File(logpath+"\\"+"finish");
        if(!file.exists()) {
            createDirectory(file.getPath());
        }
        File file1 = new File(logpath+"\\"+"receive");
        if(!file1.exists()) {
            createDirectory(file1.getPath());
        }
        LocalDate now = LocalDate.now();
        String log_receive = producelog(now);
        String log_finish = producelog(now);
        return file1.getPath()+"\\"+"receive"+log_receive+","+file.getPath()+"\\"+"finish"+log_finish;
    }


    public static void createDirectory(String directoryPath) {
        // 使用 Paths.get() 创建 Path 对象
        Path path = Paths.get(directoryPath);

        try {
            // 使用 Files.createDirectory() 创建文件夹
            Files.createDirectory(path);
            System.out.println("Directory created successfully.");
        } catch (IOException e) {
            // 处理异常
            System.err.println("Error creating directory: " + e.getMessage());
        }
    }

    private static String producelog(LocalDate currentDate) {
        // 使用日期格式化器定义日期格式
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 格式化日期为字符串
        String formattedDate = currentDate.format(dateFormatter);

        // 创建日志文件名
        String logFileName = "log_" + formattedDate + ".txt";

        // 打印日志文件名
        return logFileName;
    }
}
